/* 
 * File:   State.hxx
 * Author: enric
 *
 * Created on 26 de enero de 2012, 18:58
 */

#ifndef STATE_HXX
#define	STATE_HXX

#include <vector>
#include <string>
#include <cstdlib>

#include "Agent.hxx"

/**
 * Contains all the variables that represent a state
 */

class State
{
public:
	State();
	State( State* s );
	~State();

	std::vector<Key*>&      keys()    { return m_keys; }
	std::vector<Cell*>&     cells()   { return m_world_cells; }
	Agent*&                 agent()   { return m_agent; }

	unsigned		num_cells() { return m_world_cells.size(); }
        State*&                 father() { return m_father; }
        void                    setFather( State& father );
	std::string             to_string();

	bool operator==(State &s);
	bool operator!=(State &s);

protected:
	std::vector<Key*>       m_keys;
	std::vector<Cell*>	m_world_cells;
	Agent*                  m_agent;
        State*                  m_father;
};

inline bool State::operator==(State &s) {
	for ( unsigned k = 0; k < s.keys().size(); k++ )
		if( s.keys()[k]->location()->identifier() != keys()[k]->location()->identifier() )
			return false;

	for ( unsigned k = 0; k < s.cells().size(); k++ )
		if( s.cells()[k]->locked() != cells()[k]->locked() )
			return false;

	if( s.agent()->location()->identifier() != agent()->location()->identifier() )
		return false;

	if( s.agent()->arm_empty() != agent()->arm_empty() )
		return false;

	if( ! s.agent()->arm_empty() && ! agent()->arm_empty() )
		if( s.agent()->key_holding()->identifier() != agent()->key_holding()->identifier() )
			return false;

	      return true;
}

inline bool State::operator!=(State &s) {
        return ( *this == s ) ? false : true;
}

#endif	/* STATE_HXX */

